package com.twu.biblioteca.controller;

import com.twu.biblioteca.constant.BibliotecaConstans;
import com.twu.biblioteca.model.BibliotecaUser;

public class BibliotecaUserChecker {
    public static boolean check(BibliotecaUser user) {
        return checkNumber(user) && checkUserName(user) && checkPassword(user);
    }

    private static boolean checkPassword(BibliotecaUser user) {
        return BibliotecaConstans.AVAILABLE_PASSWORD.equalsIgnoreCase(user.getPassword());
    }

    private static boolean checkUserName(BibliotecaUser user) {
        return user.getUserName() != null;
    }

    private static boolean checkNumber(BibliotecaUser user) {
        String number = user.getNumber();
        String[] subNumbers = number.split("-");
        return subNumbers.length == 2 && subNumbers[0].length()==3 && subNumbers[1].length() ==4;
    }
}
